#include "stdafx.h"
#include "VideoInterfere.h"
#include "log.h"
/////////////////////////0.5 1  1.5  2.0  2.5  3   3.5   4    4.5 5
//int mos_to_droprate[10]={5, 5.6, 6.4, 7.5, 9, 11.25,15, 22.5, 45, 400 };
BOOL net_packet_drop(float mos)
{
	//srand((unsigned)time(NULL));//
	//int drop_rate=mos_to_droprate[mos];
	if(mos==1000)return TRUE;
	int drop_rate=mos_to_drop(mos)+2;
	Log("drop_rate:---------------------",drop_rate);
	int i=((rand()) % drop_rate);

	if( i== 0)
	{
		Log("net packet drop",0);
		return FALSE;
	}
		
	else
		Log("net packet drop",1);
		return TRUE;
}
float calculate_mos(int alg,int param1)
{
	float mos=5;
	switch(alg)
	{
	case 0:
		switch(param1)
		{
		case 0: //0.02
			mos=1.8;
			break;
		case 1:
			mos=2.9;
			break;
		case 2:
			mos=3.6;
			break;
		case 3:
			mos=4.2;
			break;
		case 4:
			mos=4.7;
			break;
		case 5:
			mos=4.9;
			break;
		default:
			break;

		}
		break;
	case 1:
		mos=4;
		break;
	case 2:
		switch(param1)
		{
		case 0: //0.02
			mos=3.0;
			break;
		case 1:
			mos=3.5;
			break;
		case 2:
			mos=4.0;
			break;
		case 3:
			mos=4.5;
			break;
		default:
			break;
		}
		break;
	case 3:
		switch(param1)
		{
		case 0: //0.02
			mos=1.0;
			break;
		case 1:
			mos=2.0;
			break;
		case 2:
			mos=3.0;
			break;
		case 3:
			mos=3.3;
			break;
		case 4:
			mos=3.7;
			break;
		case 5:
			mos=4.5;
			break;
		default:
			break;
		}
		break;
	case 4:
		mos=4;
		break;
	case 5:
		switch(param1)
		{
		case 0: //0.02
			mos=3.0;
			break;
		case 1:
			mos=3.5;
			break;
		case 2:
			mos=4.0;
			break;
		case 3:
			mos=4.5;
			break;
		default:
			break;
		}
		break;
	}
	return mos;
}
int mos_to_drop(float mos)
{
	if(mos>=3.5&& mos<4)
		return 50;
	else if (mos>=4&& mos<4.5)
	{
		return 1000;
	}else
		if(mos>=4.5)
		{
			return 1000;
		}
	return (int)(1/(-2.0/45 * mos +2.0/9 +0.0005));
}